HoboBandy's Devlog

HoboBandy's Devlog

How to install and use Hugo on Ubuntu 23.04, served by NGINX on DigitalOcean

tutorials

This is a consolidation of personal notes and tutorials I used to setup the DigitalOcean droplet for this site. I would have submitted a more step-by-step version to DO’s awesome Community Tutorials, but unfortunately their Write for DOnations program is temporarily closed.

Why Ubuntu 23.04?

The Lowkey theme used for this site requires Node v16+. Unfortunately, Ubuntu 22.04 offers v12. Thankfully, Ubuntu 23.04 offers v18+.

Initial Server Setup

Reference:

  1. Initial Server Setup with Ubuntu 22.04 by Jamon Camisso

Personal Notes:

  • Disabled root login using sshd for security reasons.
    1. Edit the sshd config file sudo nano /etc/ssh/sshd_config
    2. Comment out the line PermitRootLogin yes
    3. Restart the service sudo systemctl restart ssh
  • When generating ssh keys using puttygen on Windows, copy the public key from the textbox.

Installing NGINX on Ubuntu 23.04

Reference:

  1. How to install NGINX on Ubuntu 22.04 by Alex Garnett
  2. Certbot instructions for NGINX on Ubuntu 20.04 Focal

Personal Notes:

  • Allowed “Nginx Full” in ufw. Cerbot adds rules to redirect HTTP traffic to HTTPS.
  • Configured root for hobobandy.dev to be /var/www/hobobandy-dev, see below how this affects Hugo.
    • Allow user to manage files in that folder chown user:user /var/www/hobobandy-dev
  • Turned off server signature at bottom of error pages.
    1. Edit the nginx config sudo nano /etc/nginx/nginx.conf
    2. Uncomment the line server_tokens off; in the http block
    3. Restart NGINX for changes to take effect sudo systemctl restart nginx

Installing Hugo on Ubuntu 23.04

References:

  1. How to install and use Hugo, a static site generator on Ubuntu 14.04 by Justin Ellingwood
  2. Deploying a static Hugo site with NGINX by Gideon Wolfe
  3. Hugo Getting Started
  4. Git Clone, Push, Pull over SSH

Personal Notes:

  • Download (wget) pre-built binaries from Hugo’s Github, I chose the extended version to prevent dependencies errors from modules/themes. Install the package using dpkg -i hugo_extended_0.119.0_linux-amd64.deb
  • Hugo autocompletion fails to create the file in /etc/bash_completion.d/, workaround:
    1. Create file in a temp folder your user has access to: hugo completion bash > ~/hugo
    2. Move the file as superuser to the bash_completion folder: sudo mv ~/hugo /etc/bash_completion.d/
    3. Restart session, or type . /etc/bash_completion.d/hugo
  • In case you haven’t done this yet, prepare the ssh key and add it to your Github. (see ref 4)
  • Create a Github repo (kept mine private) for the site prior to the hugo new site command. Clone the empty repo in your preferred folder. Use the command hugo new site /home/user/my-site. Add the folders public and ressources to the .gitignore, and any other files containing sensitive information (API keys, etc.).
  • Installed the theme using git:
    1. Add theme repo as a submodule: git submodule add https://github.com/nixentric/Lowkey-Hugo-Theme.git themes/lowkey
    2. Delete hugo.toml in the Hugo root folder.
    3. Copy theme example site files and overwrite existing: cp themes/lowkey/ExampleSite/* .
    4. Install packages, from Hugo root folder: npm install
    5. All done!
  • When building the Hugo site, make sure to specify destination and clean the directory. hugo --cleanDestinationDir -d /var/www/hobobandy-dev
  • Extension matters when creating new content with Hugo:
    • hugo new content posts/some-slug/some-slug.md
  • Remember to commit and push changes to your Github repo for backup.